package client.comm.baoding.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import client.comm.baoding.R
import client.comm.baoding.api.bean.UserCards
import client.comm.baoding.databinding.ItemBank3Binding
import client.comm.commlib.base.BaseAdapter
import client.comm.commlib.base.BindingViewHoder

class Bank3Adapter : BaseAdapter<UserCards.Card> {

    constructor(context: Context) : super(context) {
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {

        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.item_bank3,
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val binding = (holder as BindingViewHoder<ItemBank3Binding>).binding
        binding.event = this
        val item = getItem(position)
        binding.e = item

        var card4 = "(${item.card_id.substring(item.card_id.length - 4, item.card_id.length)})"
        var cTypeStr = when (item.c_type) {
            0 -> "储蓄卡"
            1 -> "信用卡"
            else -> ""
        }
        binding.apply {
            typeStr = cTypeStr
        }
        if (item.bank_name != null && item.bank_name!!.isNotBlank()) {
            binding.bankNo = item.bank_name + card4
        } else {
            binding.bankNo = item.card_id
        }

//        if(item.isSelect){
//            binding.stateTv.setBackgroundResource(R.drawable.circle_red_bg_seq)
//        }else{
//            binding.stateTv.setBackgroundResource(R.drawable.circle_green_bg_seq)
//        }
//        binding.tv.text = item

    }


    var itemClick: ((e: UserCards.Card) -> Unit)? = null
//    var defItem: ((e: UserCards.Card) -> Unit)? = null

    fun runItemClick(e: UserCards.Card) {
//        e.isSelect = !e.isSelect
        itemClick?.let {
            it(e)
        }
//        notifyDataSetChanged()
    }

//    fun runDefItem(e: UserCards.Card) {
//        defItem?.let {
//            it(e)
//
//        }
//    }


}